package com.moyoutian.daogenerate.controller;

import com.fasterxml.jackson.databind.util.BeanUtil;
import com.moyoutian.daogenerate.entity.ColumnEntity;
import com.moyoutian.daogenerate.entity.ColumnId;
import com.moyoutian.daogenerate.req.ColumnByTableReq;
import com.moyoutian.daogenerate.service.ColumnService;
import lombok.AllArgsConstructor;
import org.springframework.beans.BeanUtils;
import org.springframework.data.domain.Page;
import org.springframework.stereotype.Controller;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

@Controller
@AllArgsConstructor
@RequestMapping("column")
public class ColumnController {

    private final ColumnService columnService;

    @GetMapping("/list")
    @ResponseBody
    public List<ColumnEntity> findAll(ColumnEntity columnEntity) {
        return columnService.findAll(columnEntity);
    }

    @GetMapping("/getOne")
    @ResponseBody
    public ColumnEntity getOen(ColumnId columnId) {
        return columnService.getOne(columnId);
    }

    @GetMapping("/listByTable")
    @ResponseBody
    public List<ColumnEntity> findColumnByTable(@Validated ColumnByTableReq columnByTableReq) {
        ColumnEntity columnEntity=new ColumnEntity();
        ColumnId columnId=new ColumnId();
        BeanUtils.copyProperties(columnByTableReq,columnId);
        columnEntity.setColumnId(columnId);
        BeanUtils.copyProperties(columnByTableReq,columnEntity);
        return columnService.findAll(columnEntity);
    }

}
